from keystoneauth1.identity import v3
from keystoneauth1 import session
from glanceclient import Client


# auth_url为keystone的endpoint入口
def get_keystone_session():
    auth = v3.Password(auth_url="http://192.168.10.10:5000/v3",
                       username="admin", password="000000",
                       project_name="admin", user_domain_name="demo",
                       project_domain_name="demo")
    sess = session.Session(auth=auth)
    return sess


# 调用glance
def get_glance_client():
    sess = get_keystone_session()
    glance = Client('2', "http://192.168.10.10:9292", session=sess)
    return glance


# 查询镜像列表
def list_image():
    list = glance.images.list()
    for image in list:
        print(image)
        print(image.name, image.id, image.status, image.size)



if __name__ == "__main__":
    glance = get_glance_client()
    print('xiandian55 list')
    list_image()
